#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# LINEFIT.PY                   -- by Dr. ZhuoQing 2020-09-26
#
# Note:
#============================================================

from head import *


#------------------------------------------------------------
xs = 'x'
ys = 'y'

if len(sys.argv) > 1:
    xs = sys.argv[1]

if len(sys.argv) > 2:
    ys = sys.argv[2]



#------------------------------------------------------------
if len(sys.argv) > 3:
    if sys.argv[3] == '1':
        tspinsii('from scipy.optimize        import curve_fit')

else:
    tspinsii('from scipy.optimize        import curve_fit')

tspinsii('def linefun(x, a, b):')
tspinsii('    return a*x + b\r\n    ')

tspinsii('param = (1, 0)')
tspinsii('param, conv = curve_fit(linefun, %s, %s, p0=param)'%(xs, ys))
tspinsii('printf(param)')





#------------------------------------------------------------
#        END OF FILE : LINEFIT.PY
#============================================================
